import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';

const { createConfirm } = useMessage();

enum Api {
  list = '/hd/appUserGoldDetail/list',
  save = '/hd/appUserGoldDetail/add',
  edit = '/hd/appUserGoldDetail/edit',
  deleteOne = '/hd/appUserGoldDetail/delete',
  deleteBatch = '/hd/appUserGoldDetail/deleteBatch',
  importExcel = '/hd/appUserGoldDetail/importExcel',
  exportXls = '/hd/appUserGoldDetail/exportXls',
  queryChildUserGoldList = '/hd/appUserGoldDetail/queryChildUserGoldList',
  getChildUserGoldTotal = '/hd/appUserGoldDetail/queryChildUserGoldTotal',
  queryChildUserGoldByUserId = '/hd/appUserGoldDetail/queryChildUserGoldByUserId',
  getUserGoldTotalList = '/hd/appUserGoldDetail/getUserGoldTotalList',
  currentList = '/hd/appUserGoldDetail/currentList',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

export const currentList = (params) => defHttp.get({ url: Api.currentList, params });

/**
 * 列表接口
 * @param params
 */
export const getChildUserGoldTotal = (params) => defHttp.get({ url: Api.getChildUserGoldTotal, params });

/**
 * 团队成员金币收入统计
 * @param params
 */
export const queryChildUserGoldList = (params) => defHttp.get({ url: Api.queryChildUserGoldList, params });

export const getUserGoldTotalList = (params) => defHttp.get({ url: Api.getUserGoldTotalList, params });

/**
 * 用户金币获得明细
 * @param params
 */
export const queryChildUserGoldByUserId = (params) => {
  defHttp.get({ url: Api.queryChildUserGoldByUserId, params });
}

/**
 * 删除单个
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}
